﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Citiport.Util.Language;

public partial class sandbox_test_translatedTxt : System.Web.UI.Page
{
    

    protected void Page_Load(object sender, EventArgs e)
    {
       
    }
    protected void Btn_translate_Click(object sender, EventArgs e)
    {
        //DatabaseUtil dbUtil = new DatabaseUtil();
        //String txt = "A very interesting & funny store where you can get some funny decorations for your home. Kitchen and bath items, very creative toys can also be found here. This is a brand from France. Visit the website first! And see what kinds of items you are interested in. There are also branches on Lexington Ave (64th St), in Grand Central Terminal, and Grove St.  ";
        //String txt2 = "胡同";
        //dbUtil.writeTranslatedTxt((int)DatabaseUtil.fromTables.s_profile_title, 448, txt2, Language.CHINESE_TRADITIONAL);
        this.trans_profile();
    }

    private void transForum()
    {
        ctpDataContext db = new ctpDataContext();
        DatabaseUtil dbUtil = new DatabaseUtil();
        Hashtable lang_table =dbUtil.getLangTable();
        int count = 0;
        var temp_forum = from f in db.ct_s_forums
                         select f;
        foreach (ct_s_forum csf in temp_forum)
        {
            String title = csf.title;
            String txt = csf.text;
            dbUtil.writeTranslatedTxt((int)DatabaseUtil.fromTables.forum_text, csf.no, txt, lang_table);
            dbUtil.writeTranslatedTxt((int)DatabaseUtil.fromTables.forum_title, csf.no, title, lang_table);
            count++;
        }
        Response.Write("ct_s_forum DONE: " + count + " in " + temp_forum.Count());

    }

    private void transIntro()
    {
        ctpDataContext db = new ctpDataContext();
        DatabaseUtil dbUtil = new DatabaseUtil();
        Hashtable lang_table = dbUtil.getLangTable();
        int count = 0;
        var temp_intro = from x in db.ct_s_intros
                         select x;
        count = 0;
        foreach (ct_s_intro csi in temp_intro)
        {
            String intro = csi.intro;
            dbUtil.writeTranslatedTxt((int)DatabaseUtil.fromTables.intro_intro, csi.no, intro, lang_table,"en");
            count++;
        }
        Response.Write("ct_s_intro DONE: " + count + " in " + temp_intro.Count());

    }

    private void trans_review()
    {
        ctpDataContext db = new ctpDataContext();
        DatabaseUtil dbUtil = new DatabaseUtil();
        Hashtable lang_table = dbUtil.getLangTable();
        var temp_review = from r in db.ct_s_reviews
                          select r;
        int count = 0;
        foreach (ct_s_review csr in temp_review)
        {
            String comment = csr.comment;
            dbUtil.writeTranslatedTxt((int)DatabaseUtil.fromTables.s_review_comment, csr.no, comment, lang_table);
            count++;
        }
        Response.Write("ct_s_review DONE: " + count + " in " + temp_review.Count());
    }

    private void trans_profile()
    {

        ctpDataContext db = new ctpDataContext();
        DatabaseUtil dbUtil = new DatabaseUtil();
        Hashtable lang_table = dbUtil.getLangTable();
        var temp = from p in db.ct_s_profiles
                   where p.valid == true
                   select p;
        int count = 0;
        foreach (ct_s_profile cp in temp)
        {
            String txt = cp.title.Trim();
            dbUtil.writeTranslatedTxt((int)DatabaseUtil.fromTables.s_profile_title, cp.no, txt, lang_table);
            count++;
        }
        Response.Write("ct_s_profile DONE: " + count + " in " + temp.Count());

    }

    private void trans_cityTitle()
    {
        ctpDataContext db = new ctpDataContext();
        DatabaseUtil dbUtil = new DatabaseUtil();
        Hashtable lang_table = dbUtil.getLangTable();
        var temp = from p in db.ct_profiles
                   select p;
        int count = 0;
        foreach (ct_profile c in temp)
        {
            String txt = c.title.Trim();
            dbUtil.writeTranslatedTxt((int)DatabaseUtil.fromTables.ct_profile_title, c.no, txt, lang_table, "en");
            count++;
        }
        Response.Write("ct_profile DONE: " + count + " in " + temp.Count());
    }

    private void trans_usermg()
    {
        ctpDataContext db = new ctpDataContext();
        DatabaseUtil dbUtil = new DatabaseUtil();
        Hashtable lang_table = dbUtil.getLangTable();
        var temp_message = from mg in db.user_msgs
                           select mg;
        int count = 0;
        foreach (user_msg um in temp_message)
        {
            String msg = um.message;
            dbUtil.writeTranslatedTxt((int)DatabaseUtil.fromTables.user_msg_message, um.no, msg, lang_table);
            count++;
        }
        Response.Write("ct_s_message DONE: " + count + " in " + temp_message.Count());
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        this.trans_review();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        this.trans_usermg();
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        this.transForum();
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        this.transIntro();
    }
    protected void ct_profile_Click(object sender, EventArgs e)
    {
        this.trans_cityTitle();
    }
}
